/**
 * Created by gouyx on 2017/4/26.
 */
//身份证号码正则表达式
var IDReg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
//手机号码正则表达式
var mobileReg = /^1[3|4|5|7|8][0-9]{9}$/;
//车牌号的正则表达式
var carReg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/;
//邮箱正则表达式
var emailReg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;

//var ip = "http://192.168.0.121:8080/yd";
//var ip = "http://192.168.21.114/yd";
//var ip = "http://192.168.0.117:3002/yd";
var ip = "http://mobile.ydche.com/yd";

$(".nav-left i").click(function() {
	var id = $(this).parent().parent().attr("id");
	if(id == "insuranceDetail" || id == "modifyInsurance" || id == "my-car") {
		return;
	} else {
		history.back(-1);
	}
});

$(".title-box i").click(function() {
	var _this = $(this);
	if(_this.hasClass("fa-angle-up")) {
		_this.parent().parent().siblings(".item").addClass("hide");
		_this.removeClass("fa-angle-up").addClass("fa-angle-down");
	} else {
		_this.parent().parent().siblings(".item").removeClass("hide");
		_this.removeClass("fa-angle-down").addClass("fa-angle-up");
	}
});

$(".modal .head .close").click(function() {
	$(".modal").addClass("hide");
	$(".mask").addClass("hide");
});

Date.prototype.Format = function(fmt) {
	var o = {
		"M+": this.getMonth() + 1, //月份
		"d+": this.getDate(), //日
		"h+": this.getHours(), //小时
		"m+": this.getMinutes(), //分
		"s+": this.getSeconds(), //秒
		"q+": Math.floor((this.getMonth() + 3) / 3), //季度
		"S": this.getMilliseconds() //毫秒
	};
	if(/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	for(var k in o)
		if(new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	return fmt;
}

/**
 * 保险名称编码对应的中文名称
 **/
var insurer = {
	"PAIC": "平安",
	"CPIC": "太保",
	"PICC": "人保",
	"TAIC": "天安",
	"CICP": "中华",
	"CCIC": "大地",
	"YGBX": "阳光",
	"TPIC": "太平",
	"HAIC": "华安",
	"ASTP": "安盛天平",
	"HHIC": "华海",
	"DHIC": "鼎和",
	"LIHI": "利宝",
	"FDIC": "富德",
	"CHAC": "诚泰",
	"CLPC": "国寿财",
	"HTIC": "华泰",
	"APIC": "永诚",
	"ACIC": "安诚",
	"YTBX": "亚太",
	"DBIC": "都邦",
	"YAIC": "永安",
	"CALI": "长安责任",
	"ZKIC": "紫金",
	"AHIC": "安华",
	"CINDA": "信达",
	"JTBX": "锦泰",
	"ZHONGAN": "众安"
}

var coverageCode = {

};
var config = {
	text: "正在加载...", //加载文字，默认值：加载中...
	icon: "images/loading.gif", //加载图标，默认值：一个小型的base64的gif图片
	html: false, //设置加载内容是否是html格式，默认值是false
	content: "", //忽略icon和text的值，直接在加载框中显示此值
	mask: true //是否显示遮罩效果，默认显示
}

/**
 * 检查字段是否为空
 * @param target
 * @param popInfo
 */
function judgeIsNULL(target) {
	var text = $(target).val().trim();
	if(text == "") {
		// popInfo(alertInfo,target);
		return true;
	}
	return false;
}

/**
 * 弹出信息
 * @param target
 * @param popInfo
 */
function popInfo(alertInfo, target) {
	if(alertInfo == "") {
		$(".alert").text("网络异常，请稍后重试。");
	} else {
		$(".alert").text(alertInfo);
	}
	$(".alert").show();
	var t = setTimeout(function() {
		$(".alert").hide();
		if(target) {
			$(target).focus();
		}
		clearTimeout(t);
	}, 2000);
}
/*自定义键盘*/
var flag = 0; //输入框的下标

$(".letter").click(function(ev) { //出现键盘
	console.log("3")
	$(".letter").eq(flag).focus();
	$("#keyboard").css("display", "block");
	ev.stopPropagation(); //停止事件冒泡
});

$("#keyboard").click(function(ev) { //停止事件冒泡
	ev.stopPropagation();
});

$("#keyboard span").click(function() { //输入车牌
	console.log("1")
	if(flag == 6) {
		return;
	};
	var key = $(this).text();
	$(".letter").eq(flag).val(key);
	flag++;
});

$("#keyboard p").click(function() { //删除输入的车牌
	if($(this).index() == 0) {
		$("#keyboard").css("display", "none");
	} else if($(this).index() == 8) {
		if(flag == 0) {
			return;
		};
		flag--;
		$(".letter").eq(flag).val("");
	};
});

$(window).click(function(e) {
	console.log("0")
	$("#keyboard").css("display", "none");
	
});

